package com.lanou3g.code0512.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * If there are no bugs, it was created by Chen FengYao on 2018/5/12;
 * Otherwise, I don't know who created it either
 */

@WebServlet(name = "RequestServlet",urlPatterns = "/search")
public class RequestServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");

        // 在获取参数之前  告诉tomcat 参数是utf8编码的
        // 在get请求中 这种方式不行
        //request.setCharacterEncoding("utf8");

        String keyWord = request.getParameter("keyword");


//        byte[] bytes = keyWord.getBytes("iso-8859-1");
//        keyWord = new String(bytes,"utf-8");

        response.getWriter().println("用户输入的是:" + keyWord);
    }
}
